﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOSingTowerMall;

namespace BLSingTowerMall
{
    public class TransactionProcess
    {
        public bool makePyament(ITransaction payment)
        {
            using (DBSingTowerMallEntities cntx = new DBSingTowerMallEntities())
            {


                Transaction tr = new Transaction();
                int lastTrancID;
                var count = cntx.Transactions.Count();


                if (cntx.Transactions.Count() == 0)
                {
                    lastTrancID = 1;
                }
                else
                {
                    lastTrancID = cntx.Transactions.Max(x => x.TransactionID);
                }

                tr.TransactionID = lastTrancID + 1;
                tr.BookingID = payment.BookingID;
                tr.PaymentAmount = payment.PaymentAmount;
                tr.PaymentDateTime = new DateTime();
                tr.PaymentStatus = "Successfull";



                cntx.AddToTransactions(tr);

                cntx.SaveChanges();
                return true;

            }
        }
    }
}
